Ext.define('appfe.stockor.exec.ExecHold', {
    extend: 'Ext.grid.Panel',
    xtype: 'exechold',
    // requires: ['appfe.stockor.exec.ExecHoldController',
    //     'appfe.stockor.exec.ExecHoldModel',
    //     'appfe.stockor.exec.form.ExecHoldEditForm',
    //     'appfe.stockor.exec.form.ExecHoldMonitorEditForm',
    //     'appfe.stockor.exec.form.ZenSelloutSuggestionGird'],
    controller: 'stockor.exec.ExecHold',
    viewModel: 'stockor.exec.ExecHold',
    viewConfig: {
        markDirty: false, //修改不出现红色三角标, 最新用record.commit()
        trackOver: true, // 鼠标滑过当前行时, 反显
        stripeRows: true, // 行颜色白灰条纹间隔显示
        enableTextSelection: true, // 允许选择文本
        emptyText: '点击查询按钮',
        deferEmptyText: false
    },
    //iconCls: 'x-fa fa-trophy',
    //animCollapse: false,
    //collapsible: true,
    columnLines: true, // 表格分隔线
    border: false,
    autoLoad: false,
    // frame: true,
    disableSelection: false,
    scrollable: true,
    loadMask: false, // 显示数据加载中蒙层
    selModel: {
        type: 'checkboxmodel', //带选择框
        injectCheckbox: 0, //checkbox位于哪一列，默认值为0
        mode: 'MULTI', //支持三种模式 'SINGLE' / 'SIMPLE' / 'MULTI'支持ctrl,shift的操作 
        allowDeselect: true, //mode: 'SINGLE'下才有效
        checkOnly: false //只能点击checkbox才能选中
    },
    bind: {
        store: '{execHoldStore}'
    },
    columns: {
        defaults: {
            sortable: true,
            menuDisabled: true,
            //flex: 2
            defaults: {
                sortable: true,
                menuDisabled: true
            }
        },
        items: [
            { xtype: 'rownumberer', resizable: true }, //显示行数
            { text: '代码<br/>名称', width: 85, dataIndex: 'slimsymbol', renderer: 'viewCellSymbolRender' },
            //{ text: '名称', width: 80, dataIndex: 'name' },
            { text: '数量', width: 70, dataIndex: 'holdVolume' },
            { xtype: 'numbercolumn', text: '每股成本<br/>总成本', width: 100, dataIndex: 'unitCost', align: 'right', renderer: 'viewCellCostRender' },// format: '￥0.00'
            { xtype: 'numbercolumn', text: '每股盈亏<br/>总盈亏', width: 120, dataIndex: 'unitProfit', align: 'right', renderer: 'viewCellProfitAmountRender' },
            { xtype: 'numbercolumn', text: '盈亏率', width: 130, dataIndex: 'profitRatio', align: 'right', renderer: 'viewCellProfitRatioRender' },
            { xtype: 'numbercolumn', text: '现价', width: 120, dataIndex: 'current', align: 'right', renderer: 'viewCellCurrentRender' },
            { xtype: 'numbercolumn', text: '涨跌额<br/>幅', width: 90, dataIndex: 'chg', align: 'right', renderer: 'viewCellChgPercentRender' },
            { xtype: 'numbercolumn', text: '今开<br/>昨收', width: 85, dataIndex: 'lastClose', align: 'right', renderer: 'viewCellOpenLastcloseRender' },
            { xtype: 'numbercolumn', text: '最高<br/>最低', width: 85, dataIndex: 'high', align: 'right', renderer: 'viewCellHighLowRender' },
            { xtype: 'numbercolumn', header: '成交量(万手)<br/>额(亿元)', width: 120, dataIndex: 'volume', align: 'right', renderer: 'viewCellVolumeAmountRender' },
            { xtype: 'datecolumn', text: '时价<br/>时间', width: 95, dataIndex: 'timestamp', format: 'Y-m-d <br/>H:i' },
            //{ xtype: 'datecolumn', text: '创建时间', width: 160, dataIndex: 'createDate', format: 'Y-m-d H:i:s' },
            { xtype: 'datecolumn', text: '修改<br/>时间', width: 95, dataIndex: 'modifyDate', format: 'Y-m-d <br/>H:i:s' },
            { text: '状态', dataIndex: 'status', width: 70, renderer: 'viewCellStatusRender' },
            { text: '卖出建议', dataIndex: 'suggestions', width: 200, sortable: false },
            {
                text: '智能监控价格自动卖出(招商证券)',
                columns: [
                    { text: '监控价', width: 90, dataIndex: 'monitorSelloutBarriePrice', align: 'right', sortable: false, renderer: 'monitorSelloutPriceCellRender' }, //format: '￥0.00',
                    { text: '执行价', width: 90, dataIndex: 'monitorSelloutExecPrice', align: 'right', sortable: false, renderer: 'monitorSelloutPriceCellRender' }, //format: '0.0000%', renderer: function (rate) { return Ext.util.Format.number(rate * 100, '0.00%'); }
                    { text: '执行量', width: 90, dataIndex: 'monitorSelloutExecVolume', sortable: false },
                    { text: '执行损益', width: 100, dataIndex: 'monitorSelloutExecProfit', align: 'right', sortable: false, renderer: 'monitorSelloutExecProfitCellRender' }
                ]
            },
            { text: '备注', dataIndex: 'comments', flex: 1, sortable: false, producesHTML: false, renderer: 'viewCellPlainTextRender' }
        ]
    },
    dockedItems: [
        {/* 顶部查询栏 */
            xtype: 'panel',
            reference: 'top',
            dock: 'top',
            padding: '16 10 16 10',
            frame: true,
            scrollable: true,
            layout: 'vbox',
            defaults: {
                xtype: 'container',
                layout: 'hbox',
                scrollable: true,
                width: '100%',
                border: true
            },
            items: [
                { // 第一行 container
                    items: [
                        {//左侧查询栏container
                            layout: 'column',
                            columnWidth: 0.8,
                            defaults: { margin: '0 5 0 5' },
                            items: [
                                {
                                    xtype: 'combo',
                                    name: 'queryKey',
                                    reference: 'queryKey',
                                    editable: false,
                                    bind: {
                                        store: '{queryKeyStore}'
                                    },
                                    listConfig: { itemTpl: ['<div data-qtip="值:{code},类型:{type}">{text}</div>'] },
                                    //multiSelect: true,
                                    queryMode: 'local',
                                    valueField: 'code',
                                    displayField: 'text',
                                    value: 'slimsymbol',
                                    allowBlank: false,
                                    width: 80
                                }, {
                                    xtype: 'textfield',
                                    fieldLabel: ':',
                                    labelWidth: 60,
                                    labelAlign: 'right',
                                    anchor: '100%',
                                    //width: 160,
                                    reference: 'queryValue',
                                    itemId: 'queryValue'
                                    //emptyText: '多个值由逗号分隔'
                                }, {
                                    xtype: 'combo',
                                    fieldLabel: '状态',
                                    labelAlign: 'right',
                                    labelWidth: 30,
                                    reference: 'status',
                                    editable: false,
                                    bind: {
                                        store: '{execHoldStatusStore}'
                                    },
                                    multiSelect: true,
                                    queryMode: 'local',
                                    valueField: 'code',
                                    displayField: 'text',
                                    value: ['HOLD', 'WACH'],
                                    triggerAction: 'all',
                                    width: 180
                                }, { //查询按钮
                                    xtype: 'button',
                                    text: '查询',
                                    iconCls: 'x-fa fa-search',
                                    handler: 'search'
                                }
                            ]
                        },
                        // {//右侧工具栏 container
                        //     //columnWidth: 0.2,
                        //     layout: {
                        //         type: 'hbox',
                        //         pack: 'end'
                        //     },
                        //     defaults: { margin: '0 10 0 5' },
                        //     items: [
                        //         {
                        //             xtype: 'combo',
                        //             name: 'refreshInterval',
                        //             reference: 'refreshInterval',
                        //             fieldLabel: '刷新间隔',
                        //             labelAlign: 'right',
                        //             labelWidth: 60,
                        //             editable: false,
                        //             bind: {
                        //                 store: '{refreshIntervalStore}'
                        //             },
                        //             listConfig: { itemTpl: ['<div data-qtip="{tips}">{text}</div>'] },
                        //             //multiSelect: true,
                        //             queryMode: 'local',
                        //             valueField: 'interval',
                        //             displayField: 'text',
                        //             value: '0',
                        //             allowBlank: false,
                        //             publishes: 'value',
                        //             width: 150,
                        //             listeners: {
                        //                 change: 'onRefreshIntervalChange'
                        //             }
                        //         }
                        //     ]
                        // }
                        {//右侧工具栏 container
                            items: [
                                {
                                    margin: '0 10 0 5',
                                    xtype: 'combo',
                                    name: 'refreshInterval',
                                    reference: 'refreshInterval',
                                    fieldLabel: '刷新间隔',
                                    labelAlign: 'right',
                                    labelWidth: 60,
                                    editable: false,
                                    bind: {
                                        store: '{refreshIntervalStore}'
                                    },
                                    listConfig: { itemTpl: ['<div data-qtip="{tips}">{text}</div>'] },
                                    //multiSelect: true,
                                    queryMode: 'local',
                                    valueField: 'interval',
                                    displayField: 'text',
                                    value: '0',
                                    allowBlank: false,
                                    publishes: 'value',
                                    width: 150,
                                    listeners: {
                                        change: 'onRefreshIntervalChange'
                                    }
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        { /* 底部动作按钮栏 */
            xtype: 'panel',
            reference: 'bottom',
            dock: 'bottom',
            padding: '7 5 8 10',
            frame: true,
            scrollable: true,
            layout: 'vbox',
            items: [
                { //第一行 container
                    xtype: 'container',
                    layout: 'column',
                    width: '100%',
                    scrollable: true,
                    items: [
                        {//左侧查询栏container
                            columnWidth: 0.8,
                            xtype: 'container',
                            layout: 'hbox',
                            scrollable: true,
                            items: [
                                {
                                    xtype: 'buttongreen',
                                    margin: '7 5 7 0',
                                    text: '新建',
                                    iconCls: 'x-fa fa-plus',
                                    handler: 'popupFormWin',
                                    actionType: 'insert',
                                    bind: {
                                        disabled: '{refreshing}'
                                    }
                                }, {
                                    xtype: 'buttonyellow',
                                    margin: '7 5 7 0',
                                    text: '修改',
                                    iconCls: 'x-fa fa-edit',
                                    handler: 'popupFormWin',
                                    actionType: 'update', //额外的属性传入handler方法
                                    bind: {
                                        disabled: '{refreshing}'
                                    }
                                }, {
                                    xtype: 'buttonred',
                                    margin: '7 5 7 0',
                                    text: '删除',
                                    iconCls: 'x-fa fa-remove',
                                    handler: 'onBtnDelClick',
                                    actionType: 'delete', //额外的属性传入handler方法
                                    bind: {
                                        disabled: '{refreshing}'
                                    }
                                }, {//竖线分隔符
                                    xtype: 'displayfield',
                                    margin: '5 5 0 0',
                                    align: 'right',
                                    value: '<b>|</b>',
                                    disabled: true
                                }, {
                                    xtype: 'buttonpurple',
                                    margin: '7 5 7 0',
                                    text: '编辑智能卖出监控',
                                    iconCls: 'x-fa fa-eye',
                                    handler: 'popupMonitorWin'
                                }, {//竖线分隔符
                                    xtype: 'displayfield',
                                    margin: '5 5 0 0',
                                    align: 'right',
                                    value: '<b>|</b>',
                                    disabled: true
                                }, {
                                    xtype: 'buttonpurple',
                                    margin: '7 5 7 0',
                                    text: '现价卖出分析',
                                    iconCls: 'x-fa fa-eye',
                                    handler: 'fetchCurrentPrice2SelloutAnalyze'
                                }, {//竖线分隔符
                                    xtype: 'displayfield',
                                    margin: '5 5 0 0',
                                    align: 'right',
                                    value: '<b>|</b>',
                                    disabled: true
                                }, {
                                    xtype: 'button',
                                    margin: '7 5 7 0',
                                    text: '详细卖出建议',
                                    iconCls: 'x-fa fa-book',
                                    handler: 'popupSuggests'
                                }, { //
                                    xtype: 'displayfield',
                                    text: '&nbsp;&nbsp;',
                                    disabled: true
                                }, {
                                    xtype: 'displayfield',
                                    margin: '2 5 7 0',
                                    width: 380,
                                    value: '<font color="#ff3333">自动刷新时, 冻结增删改及行选择操作</font>',
                                    bind: {
                                        hidden: '{!refreshing}'
                                    }
                                }
                            ]
                        }, {//右侧工具栏 container
                            columnWidth: 0.2,
                            layout: {
                                type: 'hbox',
                                pack: 'end'
                            },
                            items: [
                                {
                                    xtype: 'displayfield',
                                    labelWidth: 350,
                                    labelAlign: 'right',
                                    margin: '2 0 0 0',
                                    fieldLabel: '已勾选股票持仓盈亏合计',
                                    bind: {
                                        value: '{formulaTotalProfitSum}'
                                    }
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ],
    listeners: {
        render: 'onRender',
        boxready: 'onBoxReady',
        selectionchange: 'selectionChange'
    }
});
